Use list for navigations
This example demonstrates how to build a navigable list-based interface in the Scripting app. It organizes structured data into expandable sections using DisclosureGroup, and allows users to navigate to detail views using NavigationLink.
Overview
You will learn how to:
- Use
Listto display a directory of departments and staff - Use
DisclosureGroupto group related items under collapsible headers - Use
NavigationLinkto navigate to a detailed view for each item - Build reusable view components for clarity and modularity
Data Model
The example defines a nested data structure representing a company, its departments, and the staff within each department.
Sample Data
View Components
PersonRowView
A reusable component to display a person's name and phone number in a vertically stacked layout.
PersonDetailView
Displays detailed information about a selected person.
Main View Layout
The root view uses a NavigationStack and displays departments grouped in a List. Each DisclosureGroup expands to show staff members. Selecting a person navigates to their detail view.
Launching the View
Key Components
- List: Displays a vertically scrollable list of items.
- DisclosureGroup: Organizes content into expandable/collapsible sections.
- NavigationLink: Enables navigation to another view when tapped.
- NavigationStack: Provides navigation context for view transitions.
Use Cases
- Building directory-style interfaces (e.g., org charts, contact lists)
- Organizing hierarchical data with drill-down navigation
- Providing a structured browsing experience
This example offers a clean and scalable pattern for navigating through structured lists and accessing detailed information with ease.
